package com.mzj.saas.mservice.lockManager.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.lockManager.entity.SmartLockBrand;
import com.mzj.saas.mservice.lockManager.service.LockBrandService;
import com.mzj.saas.mservice.lockManager.vo.LockBrandListVO;
import com.mzj.saas.mservice.lockManager.vo.LockBrandVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 智能锁品牌管理接口
 */
@Controller
@RequestMapping("/lockBrand")
public class LockBrandController {
    @Autowired
    private LockBrandService lockBrandService;

    /**
     * 智能锁品牌列表
     *
     * @param accessToken
     * @return
     * @status 状态：0禁用 1激活
     */
    @GetMapping("/lockBrandList")
    @ResponseBody
    public ResultBean<ApiData<LockBrandListVO>> lockBrandList(@RequestHeader String accessToken,
                                                              @RequestParam(value = "status", required = false) Integer status,
                                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                                              @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockBrandService.lockBrandList(accessToken, status, pageNumber, pageSize);
    }

    /**
     * 新增智能锁品牌
     *
     * @param accessToken
     * @param name
     * @param file
     * @return
     */
    @PostMapping("/saveBrand")
    @ResponseBody
    public ResultBean<Object> saveBrand(@RequestHeader String accessToken,
                                        @RequestParam(value = "name") String name,
                                        @RequestParam(value = "file") MultipartFile file) {
        return lockBrandService.saveBrand(accessToken, name, file);
    }

    /**
     * 查看智能锁品牌
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/findBrand")
    @ResponseBody
    public ResultBean<LockBrandVO> findBrand(@RequestHeader String accessToken,
                                             @RequestParam(value = "id") Long id) {
        return lockBrandService.findBrand(accessToken, id);
    }

    /**
     * 编辑智能锁品牌
     *
     * @param accessToken
     * @param id
     * @param name
     * @param file
     * @return
     */
    @PostMapping("/updateBrand")
    @ResponseBody
    public ResultBean<Object> updateBrand(@RequestHeader String accessToken,
                                          @RequestParam(value = "id") Long id,
                                          @RequestParam(value = "name") String name,
                                          @RequestParam(value = "file", required = false) MultipartFile file) {
        return lockBrandService.updateBrand(accessToken, id, name, file);
    }

    /**
     * 激活或禁用品牌
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/updateBrandStatus")
    @ResponseBody
    public ResultBean<Object> updateBrandStatus(@RequestHeader String accessToken,
                                                @RequestParam(value = "id") Long id) {
        return lockBrandService.updateBrandStatus(accessToken, id);
    }

    /**
     * 删除智能锁品牌
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/deleteBrand")
    @ResponseBody
    public ResultBean<Object> deleteBrand(@RequestHeader String accessToken,
                                          @RequestParam(value = "id") Long id) {
        return lockBrandService.deleteBrand(accessToken, id);
    }

    /**
     * 查看智能锁品牌
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/brand")
    @ResponseBody
    public ResultBean<SmartLockBrand> getBrand(@RequestHeader String accessToken,
                                             @RequestParam(value = "id") Long id) {
        return lockBrandService.getBrand(accessToken, id);
    }
}
